Can you please explain to me what where T : class, new() means in the following line of code?
void Add<T>(T item) where T : class, new();
That is a constraint on the generic parameter T. It must be a class (reference type) and must have a public parameter-less default constructor.
That means T can't be an int, float, double, DateTime or any other struct (value type).
It could be a string, or any other custom reference type, as long as it has a default or parameter-less constructor.
Those are generic type constraints. In your case there are two of them:
where T : class
Means that the type T must be a reference type (not a value type).
where T : new()
Means that the type T must have a parameter-less constructor. Having this constraint will allow you to do something like T field = new T(); in your code which you wouldn't be able to do otherwise.
You then combine the two using a comma to get:
where T : class, new()
where T : struct
The type argument must be a value type. Any value type except Nullable can be specified. See Using Nullable Types (C# Programming Guide) for more information.
where T : class
The type argument must be a reference type, including any class, interface, delegate, or array type. (See note below.)
where T : new() The type argument must have a public parameterless constructor. When used in conjunction with other constraints, the new() constraint must be specified last.
where T : [base class name]
The type argument must be or derive from the specified base class.
where T : [interface name]
The type argument must be or implement the specified interface. Multiple interface constraints can be specified. The constraining interface can also be generic.
where T : U
The type argument supplied for T must be or derive from the argument supplied for U. This is called a naked type constraint.